package com.gsm.utils;

import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 校验类
 */
@Component
public class CheckUtils {

    /**
     * 校验字符串是否是手机号
     * @param str
     * @return true表示是手机号
     */
    public static boolean checkStrIsIphoneNo(String str) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15[0-3,5-9])|(166)|(17[3,5,6,7,8])|(18[0-9])|(19[8,9]))\\d{8}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        boolean isMatch = m.matches();
        return isMatch;
    }

    /**
     * 校验字符串是否是邮箱号
     * @param str
     * @return true表示是邮箱号
     */
    public static boolean checkStrIsEmail(String str) {
        String regex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        boolean isMatch = m.matches();
        return isMatch;
    }

    public static void main(String[] args) {
        boolean b = CheckUtils.checkStrIsIphoneNo("15251922665");
        System.out.println(b);
    }

}
